package test7;

import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;

import java.sql.SQLOutput;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2022-11-02
 * Time: 20:59
 */
public class Main {
    public static void main(String[] args) {

            Employee emo1 = new Employee(10);
            Employee emo2 = new Employee(-1);

    }


}

class Person {
    public Person() {
        System.out.println("创建一个Person");
    }
}
class Employee extends Person{
    int age;

    public Employee(int age) {
        System.out.println("创建了一个Employee");
        setAge(age);
        System.out.println("年龄为："+age);
    }

    private void setAge(int age) throws IllegalArgumentException{
        if( age>=0) {
            this.age = age;
        } else {
            throw new IllegalArgumentException("年龄不能为负数");
        }

    }
}
